Conversation
Created using spr 1.3.4
|
@llvm/pr-subscribers-pgo Author: Amir Ayupov (aaupov) ChangesFor shared libraries (.so), read the binary's build ID during load() This enables automatic build ID-based filtering of perfscript Full diff: https://github.com/llvm/llvm-project/pull/190862.diff 2 Files Affected:
diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
index 915e991e4068c..f6be04a4790fd 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
@@ -11,6 +11,7 @@
#include "MissingFrameInferrer.h"
#include "Options.h"
#include "ProfileGenerator.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/DebugInfo/PDB/IPDBSession.h"
#include "llvm/DebugInfo/PDB/PDB.h"
#include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
@@ -246,6 +247,16 @@ void ProfiledBinary::load() {
// Find the preferred load address for text sections.
setPreferredTextSegmentAddresses(Obj);
+ // For shared libraries, read build ID to filter perfscript addresses
+ // in [buildid:]addr format. Main executables use empty FilterBuildID
+ // since their addresses have no buildid prefix.
+ StringRef FileName = llvm::sys::path::filename(Path);
+ if (FileName.ends_with(".so") || FileName.contains(".so.")) {
+ auto BID = object::getBuildID(Obj);
+ if (!BID.empty())
+ FilterBuildID = llvm::toHex(BID, /*LowerCase=*/true);
+ }
+
// Load debug info of subprograms from DWARF section.
// If path of debug info binary is specified, use the debug info from it,
// otherwise use the debug info from the executable binary.
diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.h b/llvm/tools/llvm-profgen/ProfiledBinary.h
index 16218d430d78c..d5ad61d870770 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.h
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.h
@@ -28,6 +28,7 @@
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MCTargetOptions.h"
+#include "llvm/Object/BuildID.h"
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/ProfileData/SampleProf.h"
#include "llvm/Support/CommandLine.h"
@@ -337,6 +338,11 @@ class ProfiledBinary {
bool IsCOFF = false;
+ // Build ID used to filter perfscript addresses in [buildid:]addr format.
+ // For shared libraries, set to the binary's build ID.
+ // For main executables, kept empty (addresses have no buildid prefix).
+ std::string FilterBuildID;
+
void setPreferredTextSegmentAddresses(const object::ObjectFile *O);
// LLVMSymbolizer's symbolize{Code, Data} interfaces requires a section index
@@ -425,6 +431,9 @@ class ProfiledBinary {
bool isCOFF() const { return IsCOFF; }
+ // Return the build ID used for filtering perfscript addresses.
+ StringRef getFilterBuildID() const { return FilterBuildID; }
+
// Canonicalize to use preferred load address as base address.
uint64_t canonicalizeVirtualAddress(uint64_t Address) {
return Address - BaseAddress + getPreferredBaseAddress();
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Created using spr 1.3.4
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/10/builds/26233 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/226/builds/3606 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/203/builds/43007 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/206/builds/17415 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/22447 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/160/builds/35970 Here is the relevant piece of the build log for the reference |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/180/builds/36110 Here is the relevant piece of the build log for the reference |
For shared libraries (.so), read the binary's build ID during load()
using object::getBuildID() and store it as FilterBuildID. Main
executables keep FilterBuildID empty, matching the convention that
their perfscript addresses have no buildid prefix.
This enables automatic build ID-based filtering of perfscript
addresses in [buildid:]0xaddr format without requiring a CLI option.